package pers.flowerinsnow.minecraft.forge.shiftability.manager

import net.minecraftforge.common.config.Configuration
import pers.flowerinsnow.minecraft.forge.shiftability.ShiftAbility
import net.minecraftforge.common.config.Property
import java.io.File

interface ISAConfigManager {
    val file : File
    val configInstance : Configuration
    fun get(category : String, key : String, default: Boolean) : Property
    fun get(category : String, key : String, default: BooleanArray) : Property
    fun get(category : String, key : String, default: Double) : Property
    fun get(category : String, key : String, default: DoubleArray) : Property
    fun get(category : String, key : String, default: Int) : Property
    fun get(category : String, key : String, default: IntArray) : Property
    fun get(category : String, key : String, default: String) : Property
    fun get(category : String, key : String, default: Array<String>) : Property

    fun reload() : ISAConfigManager
    fun save() : ISAConfigManager
    enum class ConfigEntry(val id: Int, val category : String, val key : String, val default : Any) {
        GENERAL_ENABLE(0x00000101, "general","enable", false),
        GENERAL_PERIOD(0x00000201, "general","period", 5000);
        fun get(config : Configuration) : Property {
            if (default is Int)
                return config.get(category, key, default)
            if (default is IntArray)
                return config.get(category, key, default)
            if (default is Boolean)
                return config.get(category, key, default)
            if (default is BooleanArray)
                return config.get(category, key, default)
            if (default is Double)
                return config.get(category, key, default)
            if (default is DoubleArray)
                return config.get(category, key, default)
            if (default is String)
                return config.get(category, key, default)
            if (default is Array<*> && default.isArrayOf<String>()) {
                val default = this.default as Array<String>
                return config.get(category, key, default)
            }
            throw IllegalArgumentException("无效的默认值参数 ${this.name}")
        }
        fun get() : Property {
            return get(ShiftAbility.configManager.configInstance)
        }
    }
}